[id].vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation1></HomePageNavigation1>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 搜索框 -->
  10. <div class="search">
  11. <div class="inner">
  12. <input v-model="keywordInput" type="text" placeholder="请输入搜索内容">
  13. <button @click="goSearch">搜索</button>
  14. </div>
  15. </div>
  16. <div class="breadcrumb phone_none">
  17. <div class="inner">
  18. <span class="location">当前位置:</span>
  19. <el-breadcrumb :separator-icon="ArrowRight">
  20. <el-breadcrumb-item>
  21. <NuxtLink to="/">首页</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item>搜索</el-breadcrumb-item>
  24. </el-breadcrumb>
  25. </div>
  26. </div>
  27. <div class="breadcrumb_box pc_none">
  28. <span class=" ">当前位置:</span>
  29. <NuxtLink to="/">首页</NuxtLink>
  30. <span class=" ">&gt;</span>
  31. <span class=" ">搜索</span>
  32. </div>
  33. <div class="newsList">
  34. <div class="inner">
  35. <div class="innerLeft">
  36. <ul class="list" v-if="newsList.length >= 0">
  37. <li v-for="(item, index) in newsList" :key="index">
  38. <NuxtLink :href="getLinkPathDetail(item)" :title="item.title"
  39. :target="item.islink == 1 ? '_blank' : '_self'">
  40. <span class="listText"> {{ item.title }}</span>
  41. <span class="time phone_none ">{{ getTime(item.updated_at, 'month', 1) }}</span>
  42. </NuxtLink>
  43. </li>
  44. </ul>
  45. <div v-if="newsList.length == 0" class="empty">
  46. <div>
  47. <img src="../../public/search/empty.png" alt="暂无内容">
  48. <p>暂无搜索数据</p>
  49. </div>
  50. </div>
  51. <!-- 分页器 -->
  52. <div class="pagination pagination_phone_none" v-if="total > 0">
  53. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  54. :page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
  55. </div>
  56. <div class="pagination pagination_pc_none" v-if="total > 0">
  57. <el-pagination
  58. pager-count="5"
  59. class="mt-4"
  60. size="small"
  61. background
  62. layout=" pager "
  63. :total="total"
  64. page-size="pageSize"
  65. @change="changePage"
  66. />
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- 列表页广告二 -->
  72. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  73. <!-- 页面底部 -->
  74. <HomeFoot1></HomeFoot1>
  75. </div>
  76. </template>
  77. <script setup>
  78. //1.页面依赖 start ---------------------------------------->
  79. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  80. import { ArrowRight } from '@element-plus/icons-vue'
  81. import { ref, onMounted } from 'vue';
  82. const route = useRoute();
  83. //const pageCatids = route.query.catids;
  84. const pageCatids = ""
  85. if (route.params.id == 'search') {
  86. } else {
  87. const pageCatids = route.params.id
  88. }
  89. const pageDepartment_id = route.query.department_id;
  90. //const category_id = route.query.category_id; //获得该页面的id
  91. // const searchKey = route.query.keyword
  92. // const catids = ref([]);
  93. //关键词
  94. let total = useState("total", () => 0)
  95. let page = useState("page", () => 1)
  96. let pageSize = useState("pageSize", () => 20)
  97. //格式化跳转链接
  98. const getLinkPathDetail = (item) => {
  99. if (item.islink == 1) {
  100. return `${item.linkurl}`;
  101. } else {
  102. return `/${item.pinyin}/${item.id}.html`;
  103. }
  104. }
  105. //1.页面依赖 end ---------------------------------------->
  106. //2.页面数据 start ---------------------------------------->
  107. //2.1 广告
  108. let adImg1 = ref([]);
  109. let adImg2 = ref([]);
  110. onMounted(async () => {
  111. //从客户端获取行政职能部门 加快打开速度
  112. const { $webUrl, $CwebUrl } = useNuxtApp();
  113. //广告1
  114. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmw_search_0001`
  115. const responseAd1 = await fetch(url, {
  116. headers: {
  117. 'Content-Type': 'application/json',
  118. 'Userurl': $CwebUrl,
  119. 'Origin': $CwebUrl
  120. }
  121. });
  122. const resultAd1 = await responseAd1.json();
  123. adImg1.value = resultAd1.data[0];
  124. //广告2
  125. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmw_search_0002`
  126. const responseAd2 = await fetch(url2, {
  127. headers: {
  128. 'Content-Type': 'application/json',
  129. 'Userurl': $CwebUrl,
  130. 'Origin': $CwebUrl
  131. }
  132. });
  133. const resultAd2 = await responseAd2.json();
  134. adImg2.value = resultAd2.data[0];
  135. })
  136. // 新闻列表
  137. const newsList = ref([]);
  138. let keywordInput = ref("");
  139. //搜索
  140. let goSearch = async () => {
  141. console.log(page.value)
  142. console.log(pageSize.value)
  143. console.log(keywordInput.value)
  144. console.log(pageCatids)
  145. console.log(pageDepartment_id)
  146. const listData = await requestDataPromise('/web/selectWebsiteCategory', {
  147. method: 'GET',
  148. query: {
  149. 'page': page.value,
  150. 'pageSize': pageSize.value,
  151. 'keyword': keywordInput.value,
  152. 'cityid': pageCatids,
  153. 'department_id': pageDepartment_id
  154. },
  155. });
  156. if (listData.data.rows) {
  157. console.log(listData)
  158. newsList.value = listData.data.rows;
  159. total.value = listData.data.count;
  160. } else {
  161. newsList.value = [];
  162. total.value = 0;
  163. }
  164. }
  165. goSearch();
  166. //基于导航池搜索
  167. // let goSearchFont = async (font) => {
  168. // const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  169. // method: 'GET',
  170. // query: {
  171. // 'page': page.value,
  172. // 'pageSize': pageSize.value,
  173. // 'catid': font
  174. // },
  175. // });
  176. // newsList.value = listData.data.rows;
  177. // total.value = listData.data.count;
  178. // }
  179. // //基于导航池与关键词搜索
  180. // let goSearchFontandCid = async (font) => {
  181. // const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  182. // method: 'GET',
  183. // query: {
  184. // 'page': page.value,
  185. // 'pageSize': pageSize.value,
  186. // 'catid': category_id,
  187. // 'keyword':searchKey
  188. // },
  189. // });
  190. // newsList.value = listData.data.rows;
  191. // total.value = listData.data.count;
  192. // }
  193. //直接查新闻
  194. // const newslists = async () => {
  195. // try {
  196. // // 从地区跳转
  197. // if (route.query.catids && route.query.catids.length > 0) {
  198. // // 将字符串转换回数组,并过滤掉可能的空值
  199. // catids.value = route.query.catids.split(',').filter(id => id);
  200. // if (catids.value.length > 0) {
  201. // // 有效的 catids 数组,可以进行后续操作
  202. // console.log('接收到的分类ID数组:', catids.value);
  203. // let font = catids.value.join(",")
  204. // font = "[" + font + "]"
  205. // goSearchFont(font);
  206. // } else {
  207. // // 处理空数组情况
  208. // console.log('未接收到有效的分类ID');
  209. // }
  210. // } else {
  211. // if (category_id == undefined) {
  212. // //直接搜索 默认进来没有导航池的话 不执行搜索
  213. // goSearch();
  214. // } else {
  215. // goSearchFontandCid();
  216. // }
  217. // }
  218. // } catch (error) {
  219. // console.error(error);
  220. // }
  221. // }
  222. // newslists();
  223. // 查询导航池的方法
  224. // const newslists = async () => {
  225. // try {
  226. // // 从地区跳转
  227. // if (route.query.catids && route.query.catids.length > 0) {
  228. // // 将字符串转换回数组,并过滤掉可能的空值
  229. // catids.value = route.query.catids.split(',').filter(id => id);
  230. // if (catids.value.length > 0) {
  231. // // 有效的 catids 数组,可以进行后续操作
  232. // console.log('接收到的分类ID数组:', catids.value);
  233. // let font = catids.value.join(",")
  234. // font = "[" + font + "]"
  235. // goSearchFont(font);
  236. // } else {
  237. // // 处理空数组情况
  238. // console.log('未接收到有效的分类ID');
  239. // }
  240. // } else {
  241. // if (category_id == undefined) {
  242. // //直接搜索 默认进来没有导航池的话 不执行搜索
  243. // goSearch();
  244. // } else {
  245. // goSearchFontandCid();
  246. // }
  247. // }
  248. // } catch (error) {
  249. // console.error(error);
  250. // }
  251. // }
  252. // newslists();
  253. //分页事件
  254. let changePage = (value) => {
  255. console.log("当前页码", value);
  256. page.value = value
  257. console.log(page.value);
  258. goSearch()
  259. }
  260. //2.页面数据 end ---------------------------------------->
  261. //4.设置seo信息 start---------------------------------------->
  262. //4.1 设置seo信息
  263. const setData = await requestDataPromise('/web/getWebsiteFootInfo', {
  264. method: 'GET',
  265. query: {},
  266. });
  267. let seoTitle = setData.data.website_head.title;
  268. let seoDescription = setData.data.website_head.description;
  269. let seoKeywords = setData.data.website_head.keywords;
  270. let seoSuffix = setData.data.website_head.suffix;
  271. let seoName = setData.data.website_head.website_name;
  272. useSeoMeta({
  273. title: seoTitle + "_" + seoSuffix,
  274. meta: [
  275. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  276. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  277. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  278. ]
  279. });
  280. //4.设置seo信息 end---------------------------------------->
  281. </script>
  282. <style lang="less" scoped>
  283. @import url('@/assets/css/search.less');
  284. </style>
  285. <style lang="less" scoped>
  286. @media screen and (min-width:801px){/*pc*/
  287. .pagination_pc_none{display:none!important;}
  288. .pc_none{display:none;}
  289. }
  290. @media screen and (max-width:800px){/*ipad_phone*/
  291. .breadcrumb{margin-bottom:10px; }
  292. .breadcrumb .location{ font-size: 14px; }
  293. .breadcrumb span { font-size: 14px; }
  294. .newsList{width:100%;margin-bottom:22px;}
  295. .newsList .inner{width:92%!important;}
  296. .newsList .inner .innerLeft > .list > li{width:96%;margin:0px auto;}
  297. .newsList .inner .innerLeft{width:100%;border-top:solid 1px #DD7D18;}
  298. .newsList .inner .innerLeft > .list > li{line-height:50px;}
  299. .newsList .inner .innerLeft > .list > li > a{
  300. width:100%;display:block; height:50px;line-height:50px;font-size:16px;
  301. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  302. }
  303. .newsList .inner .innerLeft > .list > li a{float:left;width:92%; }
  304. .newsList .inner .innerLeft > .list > li:nth-of-type(-n+2)::after{display: block;height:18px;margin:10px 0px 0px 0px;
  305. font-size:12px;line-height:18px;float:right;}
  306. .newsList .inner .innerLeft > .pagination{width:100%;}
  307. .newsList .inner .innerLeft > .list{margin:10px auto 10px;}
  308. .newsList .inner .innerLeft > .pagination{margin-bottom:11px;}
  309. .newsList .inner .innerRight {width:100%;display:none;}
  310. .index_foot{margin-top:11px;}
  311. .search{ overflow:hidden;height:auto;
  312. width:92%;margin:10px auto;
  313. .inner{width:100%;display:flex;height:auto;padding:0;}
  314. .inner > input{ flex:1;width:auto;line-height:33px;height:33px;box-sizing:border-box;font-size:14px;}
  315. .inner > button{width:auto;padding:0px 8px;line-height:33px;height:33px;font-size:14px;}
  316. }
  317. ::v-deep .el-pager li{
  318. margin:0px 4px!important;
  319. }
  320. .advert_box{width:92%;margin:0px auto;}
  321. .pagination_phone_none{display:none!important;}
  322. .newsList .inner .innerLeft > .list > li{line-height:40px;height:40px;}
  323. .newsList .inner .innerLeft > .list > li a{line-height:40px;height:40px;}
  324. .newsList .inner .innerLeft > .list > li:nth-child(5n){
  325. height:auto;
  326. padding-bottom:11px;
  327. margin-bottom:11px;
  328. }
  329. .breadcrumb_box{
  330. height:22px;width:100%;margin:10px auto;
  331. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  332. width:92%;
  333. font-size:14px;
  334. color:#666;
  335. *{
  336. font-size:14px;
  337. display:inline ;
  338. color:#666;
  339. line-height:22px;height:22px;
  340. margin-right:5px;
  341. }
  342. }
  343. .newsList .inner .innerLeft .list li .listText{width:100%;}
  344. .newsDetail .inner .innerLeft .LeftTop > p{height:auto;}
  345. .phone_none{display:none;}
  346. }
  347. </style>